package cn.tpshion.shop.controller;

import cn.tpshion.shop.common.R;
import cn.tpshion.shop.domain.dto.LoginDTO;
import cn.tpshion.shop.domain.dto.OneKeyLoginDTO;
import cn.tpshion.shop.domain.dto.RegisterDTO;
import cn.tpshion.shop.domain.vo.LoginVO;
import cn.tpshion.shop.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    public R<LoginVO> login(@RequestBody LoginDTO dto) {
        return R.ok(authService.login(dto));
    }

    @PostMapping("/oneKeyLogin")
    public R<LoginVO> oneKeyLogin(@RequestBody OneKeyLoginDTO dto) {
        return R.ok(authService.oneKeyLogin(dto));
    }

    @PostMapping("/register")
    public R<LoginVO> register(@RequestBody RegisterDTO dto) {
        return R.ok(authService.register(dto));
    }

    @GetMapping("/authKey")
    public R<String> authKey() {
        return R.ok(authService.authKey());
    }

    @GetMapping("/logout")
    public R<Void> logout() {
        authService.logout();
        return R.ok();
    }
}
